﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Ghasam.Business.Services;
using Ghasam.Business.Domain.Entity;
using Mani.Common;

public partial class BasicSalaryPage : BasePage {

    public override string ActionName {
        get {
            return "vw_basicsalary";
        }
    }

    private IEmployeeService employeeService;
    public IEmployeeService EmployeeService {
        get { return employeeService; }
        set { employeeService = value; }
    }

    private IBasicSalaryService basicSalaryService;
    public IBasicSalaryService BasicSalaryService {
        get { return basicSalaryService; }
        set { basicSalaryService = value; }
    }
    
    protected void Page_Load(object sender, EventArgs e) {

        if (!Page.IsPostBack) {
            LoadEmployeeSalaryInfo();
        }
    }

    private void LoadEmployeeSalaryInfo() {
        if (Request["employeeId"] == null)
            return;

        int employeeId = Convert.ToInt32(Request["employeeId"]);
        Employee employee = EmployeeService.GetById(employeeId);
        BasicSalary s = BasicSalaryService.GetEmployeeSalaryInfo(employee);
        lblEmployeeName.Text = employeeService.GetById(employeeId).FullName;

        if ( s == null )
            return;

        txtSalaryId.Text = s.Id.ToString();
        txtBaseSalary.Text = s.BaseSalary.ToString();
        txtChildrenExtra.Text = s.ChildrenExtra.ToString();
        txtGoodsExtra.Text = s.GoodsExtra.ToString();
        txtHomeExtra.Text = s.HomeExtra.ToString();
        txtInformalSalary.Text = s.InformalSalary.ToString();
        txtOffTimePerHour.Text = s.OffTimePerHour.ToString();
        txtOverTimePerHour.Text = s.OverTimePerHour.ToString();
        txtTaxPrice.Text = s.TaxPrice.ToString();
    }

    protected void btnSave_Click(object sender, EventArgs e) {

        BasicSalary s = null;

        if (String.IsNullOrEmpty(txtSalaryId.Text)) {
            s = new BasicSalary();
            s.CreateDate = DateTime.Now;
        }
        else
            s = BasicSalaryService.GetSalary(Convert.ToInt32(txtSalaryId.Text));

        s.BaseSalary = Convert.ToSingle(txtBaseSalary.Text);
        s.ChildrenExtra = Convert.ToSingle(txtChildrenExtra.Text);
        s.GoodsExtra = Convert.ToSingle(txtGoodsExtra.Text);
        s.HomeExtra = Convert.ToSingle(txtHomeExtra.Text);
        s.InformalSalary = Convert.ToSingle(txtInformalSalary.Text);
        s.OffTimePerHour = Convert.ToSingle(txtOffTimePerHour.Text);
        s.OverTimePerHour = Convert.ToSingle(txtOverTimePerHour.Text);
        s.TaxPrice = Convert.ToSingle(txtTaxPrice.Text);
        s.ModifyStamp = DateTime.Now;
        Employee employee = employeeService.GetById(Convert.ToInt32(Request["employeeId"]));
        s.Employee = employee;

        BasicSalaryService.Save(s);
        lblMessage.Text = "تغییرات با موفقیت ذخیره شد";
    }
}
